package com.smart.community.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.community.admin.common.qo.SysUserQo;
import com.smart.community.admin.common.vo.SysUserVo;
import com.smart.community.admin.service.SmsService;
import com.smart.community.admin.service.SysUserService;
import com.smart.community.common.base.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 重点
 * 了解阶段
 *
 * @author zhangwei
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户中心Api接口管理文档")
@Slf4j
public class SysUserController {
    @Resource
    private SmsService smsService;
    @Resource
    private SysUserService sysUserService;

    /*
     * path 参数在请求路劲中
     * header 请求头
     * query  请求行
     * body   请求体
     * from
     */

    @ApiOperation("分页查询用户信息")
    @ApiImplicitParams({
            //
            @ApiImplicitParam(name = "page", value = "页码", paramType = "path"),
            //
            @ApiImplicitParam(name = "page", value = "size", paramType = "path"),
            //
            @ApiImplicitParam(name = "sysUserQo", value = "用户参数请求对象", paramType = "body")})
    @PostMapping("/list/{page}/{size}")
    //cache:user:SysUserController:list:page:1:size:10:username:admin     ResponseResult<Page<SysUserVo>>
    public ResponseResult<Page<SysUserVo>> list(@PathVariable int page, @PathVariable int size, @RequestBody SysUserQo sysUserQo) {
        return ResponseResult.success(null);
    }

    @ApiOperation("获取验证码")
    @ApiImplicitParam(name = "phone", value = "手机号")
    @PostMapping("/verify/code")
    public ResponseResult<String> verificationCode(String phone) {
        return ResponseResult.success(smsService.sendSms(phone));
    }

    @PostMapping("/phone/login/")
    public ResponseResult<String> loginPhone(String phone, String code) {
        return ResponseResult.success(sysUserService.loginPhone(phone, code));
    }
}
